﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace tema_cars
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string nume, marca, tip, numemasina, raspuns;
                int varsta;
                bool meniu = true;

                Console.Write("Numele clientului : ");
                nume = Console.ReadLine();
                Console.Write("Varsta clientului : ");
                varsta = System.Convert.ToInt32(Console.ReadLine());

                Customer client = new Customer(nume, varsta);
                CarFactory factory = Pool.Instance();

                while (meniu==true)
                {
                    Console.WriteLine( "\n!!-----Menu------!!");
                    Console.WriteLine("1. Achizitionare masina !");
                    Console.WriteLine("2. Afiseaza lista de masini a clientului !");
                    Console.WriteLine("3. Afisati toate masinile din Factory !");
                    Console.WriteLine("4. Adaugati o masina in Factory !");
                    Console.WriteLine("5. Stergeti o masina achizitionata din lista de masini a clientului");
                    Console.WriteLine("0. Exit !");
                    Console.Write("Alege: ");

                    int option = System.Convert.ToInt32(Console.ReadLine());
                    if (option == 1)
                    {
                        Console.Write("<--Introduceti numele masinii : ");
                        numemasina = Console.ReadLine();

                        Console.Write("<--Introduceti tipul caroseriei (coupe/mini/sedan) : ");
                        tip = Console.ReadLine();

                        
                        Automobil aux = new TipAutomobil();
                        aux = factory.getMasina(numemasina);

                        if (aux.getType() == tip.ToLower())
                        {
                            Console.WriteLine("\n\x00B0\x00B0 Masina dorita de dumneavoastra se afla stoc!! \x00B0\x00B0 \n");
                            Console.Write("<-> Masina aleasa de dvs este aceasta : ");
                            aux.print();

                            Console.WriteLine("\n<**> Doriti achizitionarea acesteia ? <da/nu> \n");
                            Console.Write("Raspuns: ");
                            raspuns = Console.ReadLine();

                            if (raspuns == "da")
                            {
                                client.addAutomobil(aux);
                                Console.WriteLine(" Masina achizionata !!");
                                factory.delete(aux);
                            }
                        }
                        else
                        {
                            Console.WriteLine("\n\x00B0\x00B0Ne pare rau dar masina dorita de dumneavoastra nu se afla stoc!! \x00B0\x00B0 \n");
                            Console.WriteLine("\x00B0\x00B0Pentru a vedea ce masini avem in stoc alegeti optiunea nr.3 \x00B0\x00B0 \n");
                        }
                    }

                    if (option == 2)
                    {
                        client.print();
                    }

                    if (option == 3)
                    {
                        factory.print();
                    }

                    if (option == 4)
                    {
                        factory.adauga();
                    }

                    if (option == 5)
                    {
                        client.deleteAutomobil();
                    }

                    if (option == 0)
                    {
                        meniu=false;
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("Eroare !!");
            }
        }
    }
}
